package com.guslegend.controller;



import com.guslegend.controller.request.ShortLinkAddRequest;
import com.guslegend.controller.request.ShortLinkDelRequest;
import com.guslegend.controller.request.ShortLinkPageRequest;
import com.guslegend.controller.request.ShortLinkUpdateRequest;
import com.guslegend.service.ShortLinkService;
import com.guslegend.utils.JsonData;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/link/v1")
public class ShortLinkController {

    @Autowired
    private ShortLinkService shortLinkService;


    /**
     * 新增短链
     * @param request
     * @return
     */
    @PostMapping("add")
    public JsonData createShortLink(@RequestBody ShortLinkAddRequest request){

        JsonData jsonData = shortLinkService.createShortLink(request);

        return jsonData;
    }


    /**
     * 分页查找短链
     */

    @RequestMapping("page")
    public JsonData pageByGroupId(@RequestBody ShortLinkPageRequest request){


        Map<String,Object> result = shortLinkService.pageByGroupId(request);

        return JsonData.buildSuccess(result);

    }


    /**
     * 删除短链
     * @param request
     * @return
     */
    @PostMapping("del")
    public JsonData del(@RequestBody ShortLinkDelRequest request){

        JsonData jsonData = shortLinkService.del(request);

        return jsonData;
    }





    /**
     * 更新短链
     * @param request
     * @return
     */
    @PostMapping("update")
    public JsonData update(@RequestBody ShortLinkUpdateRequest request){

        JsonData jsonData = shortLinkService.update(request);

        return jsonData;
    }



}


